package com.javaee.controller;

import com.javaee.entity.TeachingClass;
import com.javaee.service.TeachingClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/TeachingClass")
public class TeachingClassController {
    @Autowired
    private TeachingClassService teachingClassService;

    @PostMapping
    public Result create(@RequestBody TeachingClass teachingClass) {
        boolean flag = teachingClassService.create(teachingClass);
        String msg = flag ? "创建成功" : "创建失败，请重试！";
        return new Result(flag ? Code.ADD_OK:Code.ADD_ERR,flag,msg);
    }

    @PostMapping("/related")
    public Result related(@RequestBody TeachingClass teachingClass) {
        boolean flag = teachingClassService.related(teachingClass);
        String msg = flag ? "关联成功" : "关联失败，请重试！";
        return new Result(flag ? Code.UPDATE_OK:Code.UPDATE_ERR,flag,msg);
    }

    @PostMapping("/allocate")
    public Result allocate(@RequestBody TeachingClass teachingClass) {
        boolean flag = teachingClassService.allocate(teachingClass);
        String msg = flag ? "分配成功" : "分配失败，请重试！";
        return new Result(flag ? Code.UPDATE_OK:Code.UPDATE_ERR,flag,msg);
    }
}
